#-*- coding:gbk -*-
import os
import os.path
import MySQLdb
import datetime
import gc

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='111qqq!',
        db ='test',
        charset='gbk'
        )
cur = conn.cursor()                                  
sqli="insert into test values(%s)"
sqlse = "SELECT id,path FROM test"
sqlsu = "UPDATE test set success = 0 where id=(%s)"
begin = datetime.datetime.now()
path = cur.execute(sqlse)
f = open("message.log", "w")
print "watch message.log ..."
for mkdir in cur.fetchmany(path):
    id = mkdir[0]
    olddir = mkdir[1]
    newdir ="d:\\test\\"+olddir[3:]
    print >> f, "%s %d" % ("recentId:",id)
    if not os.path.exists(newdir):
        #print >> f, "%s %d" % ("lostId:",id)
        try:
            cur.execute(sqlsu,(id))
        except Exception,e:
            print >> f, "%s" % (e)    
f.close()
end = datetime.datetime.now()

print end-begin
cur.close()
conn.commit()
conn.close()

